** Import the population data: 
frame change default

forvalues num= 2016(1)2022 {

frame create pop_`num'
frame change pop_`num'

import excel "$root/Data/Original/je-d-01.02.03.04.xlsx", sheet("`num'") cellrange(A6:B47)

rename A region
rename B pop
gen year=`num'


replace region=trim(region)



}

frame change pop_2022



forvalues i=2016/2021 {
frameappend pop_`i', drop
}

gen reg_canton=""
replace reg_canton="AG" if region=="Aargau"
replace reg_canton="AI" if region=="Appenzell I. Rh."
replace reg_canton="AR" if region=="Appenzell A. Rh."
replace reg_canton="BE" if region=="Bern"
replace reg_canton="BL" if region=="Basel-Landschaft"
replace reg_canton="BS" if region=="Basel-Stadt"
replace reg_canton="FR" if region=="Freiburg"
replace reg_canton="GE" if region=="Genf"
replace reg_canton="GL" if region=="Glarus"
replace reg_canton="GR" if region=="Graubünden"
replace reg_canton="JU" if region=="Jura"
replace reg_canton="LU" if region=="Luzern"
replace reg_canton="NE" if region=="Neuenburg"
replace reg_canton="NW" if region=="Nidwalden"
replace reg_canton="OW" if region=="Obwalden"
replace reg_canton="SG" if region=="St. Gallen"
replace reg_canton="SH" if region=="Schaffhausen"
replace reg_canton="SO" if region=="Solothurn"
replace reg_canton="SZ" if region=="Schwyz"
replace reg_canton="TG" if region=="Thurgau"
replace reg_canton="TI" if region=="Tessin"
replace reg_canton="UR" if region=="Uri"
replace reg_canton="VD" if region=="Waadt"
replace reg_canton="VS" if region=="Wallis"
replace reg_canton="ZG" if region=="Zug"
replace reg_canton="ZH" if region=="Zürich"

drop if reg_canton==""
sort reg_canton year
by reg_canton: ipolate pop year, gen(pop_expol) epolate

replace pop=pop_expol if missing(pop)

save "$root/Data/Original/population.dta", replace
